#!/usr/bin/env python
from django.forms.widgets import Input, Widget
from django.utils.encoding import force_unicode
from django.utils.safestring import mark_safe
from django.forms.util import flatatt

class StaticInput( Input ):
    input_type = "text"
    def render(self, name, value, attrs=None):
        size = int(len(str(value)))
        if size < 40:
            size = 40
        # set the input as readonly
        extra_attrs = { "readonly": "readonly", "style": "background-color:#eee;", "size": size, }
        attrs.update( extra_attrs )

        # make html code
        final_attrs = self.build_attrs(attrs, type=self.input_type, name=name)
        if value != '':
            final_attrs['value'] = force_unicode(value)
        return mark_safe(u'<input%s />' % flatatt(final_attrs))
    
class CascadeChoices( Widget ):
    choices = 1
    def render(self, name, value, attrs=None):
        return """<a href="#">laji</a>"""